#ifndef QUERYWIDGET_H
#define QUERYWIDGET_H

#include "common/baseeditor.h"
#include "m_fhs.h"
#include "editdialog.h"

namespace Ui {
class QueryWidget;
}

class QueryWidget : public BaseEditor
{
    Q_OBJECT

public:
    explicit QueryWidget(QWidget *parent);
    ~QueryWidget();

    void setConnection(const QString &connectionName);
    void prepareStatement(const QMap<QString, QString> &map);
    void generateMenu();
    void updateMenu();
    void updateView();
    void setHeaderData();
    void editItem();

    void query(const QString &sql, const QString &kw);

signals:
    void showMessage(const QString &message);
    void transferLog(const QString &log);

protected:
    void keyPressEvent(QKeyEvent *event);

private slots:
    void on_tableView_doubleClicked(const QModelIndex &index);

    void on_in_code_returnPressed();
    void on_in_name_returnPressed();
    void on_btn_codeClear_clicked();
    void on_btn_nameClear_clicked();

private:
    Ui::QueryWidget *ui;

    QSqlQueryModel *queryModel;
    QSqlDatabase db;
    QMap<QString,QString> statements;
    EditDialog *editDialog;
};

#endif // QUERYWIDGET_H
